﻿// JScript 文件

//$(function () {
//    // setup ul.tabs to work as tabs for each div directly under div.panes
//    $("ul.tabs").tabs("div.panes > div");
//});

// 添加节点事件实现
function selectTypeAction() {

    var loader = new Ext.tree.TreeLoader({
        url: 'ashx/ProductType_GetAll.ashx'
    });

    loader.on('beforeload', function (treeloader, node) {
        treeloader.baseParams = {
            id: node.id
        };
    }, loader);


    var root = new Ext.tree.AsyncTreeNode({
        text: '商品类型',
        draggable: false,
        id: 'root'
    });



    var tree = new Ext.tree.TreePanel({
        width: 300,
        id: 'tree-mianban',
        title: '商品类型列表',
        animate: true,
        enableDD: true,
        containerScroll: false,
        root: root,
        loader: loader,
        containerScroll: false,
        border: true


    });

    var treeEditer = new Ext.tree.TreeEditor(Ext.getCmp('tree-mianban'), {
        id: 'tree-Manage',
        allowBlank: false
        // 输入值不可以为空
    });
    
    tree.expand();
    root.expand(false, false);
    
    // 添加点击事件
    tree.on('click', function (node) {
        if (node.id != 'root') {
//            $("#txtType").val(node.text);
//            $("#txtTypeID").val(node.id);
            document.getElementById("txtType").value = node.text;
            document.getElementById("txtTypeID").value = node.id;
            selectTypeWin.hide();
        }
    });


    var selectTypeWin = new Ext.Window({
        width: 340,
        height: 450,
        title: "选择类型",
        maximizable: true,
        items: [tree]

    });
    selectTypeWin.show();
};

Ext.onReady(function () {
    var tabs = new Ext.TabPanel({
        renderTo: 'tabs1',
        width: 800,
        activeTab: 0,
        frame: true,
        defaults: { autoHeight: true },
        items: [
        { contentEl: 'tabBase', title: '基本信息' },
        { contentEl: 'tabImg', title: '图片' },
        { contentEl: 'tabDes', title: '详细描述' }
         ]
   });
   
   this.delSizeMat = function _delSizeMat (fileName) 
    {
        var proID = document.getElementById("txtID").value;
        if(fileName == "")
        {
            proID("请选择要删除的记录！");
            return;
        } 
        var myMask = new Ext.LoadMask(Ext.getBody(), {
            msg: "Please wait..."
        });
        myMask.show();
        Ext.Ajax.request({
            url: 'ashx/ProductPic_Del.ashx',
            params: {
                productID: proID,
                picName: fileName
            },
            success: function (response) {
    
                var success = Ext.util.JSON.decode(response.responseText).success;
                var msgRet = Ext.util.JSON.decode(response.responseText).msg;
                if (success) {
                    myMask.hide();
                    var tbl = document.getElementById("tblShowPics");
                    var rows = tbl.rows;
                    for(var i=0;i<rows.length;i++)
                    {
                        var row = rows[i]; 
                        if(row.getAttribute("PathFile") == fileName)
                        {
                            tbl.deleteRow(i);
                            break;
                        }
                    };
 
                } else {
                    myMask.hide();
                    Ext.MessageBox.show({
                        title: '失败提示',
                        msg:msgRet,
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.ERROR
                    });

                }
            },
            failure: function () {
                myMask.hide();
                RetsetState();
                
                Ext.MessageBox.show({
                    title: '失败提示',
                    msg: '系统错误，请联系管理员',
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.ERROR
                });

            }
        });
        
        
  
    }
    
});

function DeleteImg(imgName)
{
    delSizeMat(imgName);
}
var i=1;
function addFile(){
    if(i<6){
        var str='<br><input  type="file" name="FileShow" runat="server" style="width:380px;"/>';
        document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str);
    }else
    {
        alert("您一次最多只能上传6张图片！");
    }
    i++;
}


function isNumber(oNum) 
   { 
  if(!oNum) return false; 
  var strP=/^\d+(\.\d+)?$/; 
  if(!strP.test(oNum)) return false; 
  try{ 
  if(parseFloat(oNum)!=oNum) return false; 
  } 
  catch(ex) 
  { 
   return false; 
  } 
  return true; 
   }